#!/bin/sh

. ../../func

# GOES TO INITRD

URL=https://www.kernel.org/pub/linux/utils/kernel/kmod
SRC=kmod
PKG=kmod_static
VER=25
COMP=tar.xz
DESC=""
DEPS=
CAT=BuildingBlock
CWD=`pwd`

build() {
	cd ${SRC}-${VER}
	opts="--prefix=/
--bindir=/bin
--sysconfdir=/etc
--with-rootlibdir=/lib"
	_configure
	sed -i 's|^LDFLAGS = *|LDFLAGS = -all-static|' Makefile
	_make ${MKFLG} LDFLAGS=-all-static
	abort_if_file_not_found tools/kmod
	install -d -m 0755 $CWD/${PKG}-${VER}-${ARCH}/bin
	_install tools/kmod $CWD/${PKG}-${VER}-${ARCH}/bin
	cd -
}

package() {
	# add this recipe
	install -d -m 0755 ./${PKG}-${VER}-${ARCH}/build
	cat ${PKG}.petbuild > ./${PKG}-${VER}-${ARCH}/build/$PKG-build-recipe
	# move, don't package
	cp -a --remove-destination ./${PKG}-${VER}-${ARCH}/* ../../00_${ARCH}
	rm -r ${SRC}-${VER}
	rm -r ${PKG}-${VER}-${ARCH}
	echo "moved to initrd"
	echo "done!"
}

# main
retrieve "${SRC}-${VER}.${COMP}"
[ "$DLD_ONLY" = "yes" ] && exit
extract ${SRC}-${VER}.${COMP}
build
package
